//统计访问量图
import { Line  } from '@antv/g2plot';
import { useEffect} from "react";
import {request} from '../../../utils';
import axios from 'axios';

const data = [
    { year: '05-28', value: 3 },
    { year: '05-29', value: 4 },
    { year: '05-30', value: 3.5 },
    { year: '05-31', value: 5 },
    { year: '06-01', value: 4.9 },
    { year: '06-02', value: 6 },
    { year: '06-03', value: 7 },
    { year: '06-04', value: 9 },
    { year: '06-05', value: 1 },
  ];

const VisitorVolume = () => {
    useEffect(() => {
      // const body = new URLSearchParams();
      // body.append('code', 'RE_SYS_TOOL');
      // body.append('data', '{"type":"scan","packagename":"nc.bs.sip"}');
      const body = {
        code: 'RE_SYS_TOOL',
        data: {"type":"scan","packagename":"nc.bs.sip"}
      };
      request.post('service/ItfplatformService', body)
        .then(response => {
          // 处理响应
        })
        .catch(error => {
          // 处理错误
        });
      // request.post('/api/service/ItfplatformService', params);
      // axios({url:'api/service/ItfplatformService',body})
      // request({
      //     method: 'post',
      //     url: '/service/ItfplatformService',
      //     data: {
      //         code: 'RE_SYS_TOOL',
      //         data: {"type":"scan","packagename":"nc.bs.sip"}
      //     }
      //   }).then(res => {
      //     if(res && res.status === 200){
      //         // 响应成功的回调
      //         console.log('test1')
      //     }else{
      //         // 响应失败
      //         console.log('test2')
      //     }
      // });
    //   const fetchData = async () => {
      //     const result = await axios(`http://127.0.0.1:9003/service/ItfplatformService`)
      //     console.log('test'+result)
      //     debugger
      // }
      // fetchData();
        const line = new Line('container', {
            data,
            xField: 'year',
            yField: 'value'
        });
        line.render();
        // 返回一个清理函数，在组件卸载或下次渲染前执行
        return () => {
            // 如果图表实例存在，则销毁它
            if (line) {
                line.destroy();
            }
        };
      }, []);
    return <div id="container" style={{ width: '400px', height: '400px' }}></div>
  };
  export default VisitorVolume;
  
  